package com.epfly.promo.activity.dao;

import com.epfly.promo.activity.entity.ActivityObjectEntity;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;
@Mapper
public interface ActivityObjectMapper extends BaseMapper<ActivityObjectEntity>, InsertListMapper<ActivityObjectEntity> {


    @Delete(value = "delete from tbl_activity_object where activity_id = #{activityId} and del_flag = 0")
    int deleteByActivityId(@Param(value = "activityId") Long activityId);


    @Results(id = "activityObjectMapperBaseResultMap", value = {
            @Result(column = "activity_id", property = "activityId"),
            @Result(column = "related_object_id", property = "relatedObjectId")
    })


    @ResultMap(value = "activityObjectMapperBaseResultMap")
    @Select(value = "select related_object_id from tbl_activity_object where activity_id = #{activityId} and del_flag = 0 ")
    List<ActivityObjectEntity> findByActivityId(@Param(value = "activityId") Long activityId);

    @ResultMap(value = "activityObjectMapperBaseResultMap")
    @Select(value = "select activityId, related_object_id from tbl_activity_object where activity_id = #{activityId} and related_object_id = #{relatedObjectId} and del_flag = 0 ")
    ActivityObjectEntity findByActivityIdAndRelatedObjectId(@Param(value = "activityId") Long activityId, @Param(value = "relatedObjectId") String relatedObjectId);
}
